﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Globalization;
using System.Resources;

namespace WLS
{
    public partial class record : Form
    {

        upload fr1;
        title fr2;

        ArrayList video;
        set all;
        all_setting p;
        string format;
        public record(set all_, ref all_setting _jazyk)
        {
            InitializeComponent();
            video = (ArrayList)((set)all_).videos;
            all = all_;
            p = _jazyk;
            p.JazykZmenen += new all_setting.ZmenaJazyku(jazyk_JazykZmenen);
            jazyk_JazykZmenen(p.jazyk);
        }

        /// <summary>
        /// Změní jazyk
        /// </summary>
        /// <param name="jazyk"></param>
        void jazyk_JazykZmenen(string jazyk)
        {
            CultureInfo cultura = CultureInfo.CreateSpecificCulture(jazyk);
            ResourceManager manager = new ResourceManager("WLS.Res", typeof(record).Assembly);
            button1.Text = manager.GetString("addvideo", cultura);
            menuItem1.Text = manager.GetString("back", cultura);
            menuItem2.Text = manager.GetString("next", cultura);
            this.Text = manager.GetString("addvideosmain", cultura);
            format = manager.GetString("format", cultura);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double size;
            //string size_text;



            //OpenFileDialog opn_f = new OpenFileDialog();
            //opn_f.Filter = Files1;
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {
                FileInfo TheFile = new FileInfo(openFileDialog1.FileName.ToString());
                string[] nazev_souboru = TheFile.Name.Split('.');
                string nazev_soub = nazev_souboru[0];
                for (int i = 1; i < nazev_souboru.Length - 1; i++)
                    nazev_soub += "." + nazev_souboru[i];
                //string filter = "*.wmv;*.mpg;*.mpeg;*.mp4;*.avi;*.mov;*.flv";
                if (openFileDialog1.Filter.IndexOf(nazev_souboru[nazev_souboru.Length - 1].ToLower()) > -1)
                {
                    size = TheFile.Length;
                    video.Add(new data(nazev_soub, 0, nazev_souboru[nazev_souboru.Length - 1], size, TheFile.CreationTime.Day + "/" + TheFile.CreationTime.Month + "/" + TheFile.CreationTime.Year, TheFile.FullName,false,new silverlights("",""),new youtube("","",-1,"",false)));
                    int last = video.Count - 1;
                    if (fr2 == null) fr2 = new title((data)video[last], ref p);
                    else fr2.Tag = (data)video[last];
                    fr2.ShowDialog();
                    if (((data)video[last]).path == "")
                    {
                        video.RemoveAt(last);
                        listBox1.Items.Clear();
                        foreach (data v in video)
                        {
                            listBox1.Items.Add(v.nazev);
                        }

                    }
                    else
                        listBox1.Items.Add(((data)video[last]).nazev);
                }
                else
                    MessageBox.Show(format);
            }
        }


        private void record_Load(object sender, EventArgs e)
        {

            if (this.Tag != null)
            {
                all = (set)this.Tag;
                video = (ArrayList)((set)all).videos;
            }
            listBox1.Items.Clear();
            foreach (data v in video)
            {
                listBox1.Items.Add(v.nazev);
            }
        }


        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            if (fr2 == null) fr2 = new title((data)video[index], ref p);
            else fr2.Tag = (data)video[index];

            fr2.ShowDialog();
            if (((data)video[index]).path == "")
            {
                video.RemoveAt(index);
                listBox1.Items.Clear();
                foreach (data v in video)
                {
                    listBox1.Items.Add(v.nazev);
                }

            }
            else
                listBox1.Items[index] = (((data)video[index]).nazev);
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            if (fr1 == null) fr1 = new upload(all, ref p);
            else fr1.Tag = all;
            fr1.ShowDialog();

            listBox1.Items.Clear();
            foreach (data v in video)
            {
                listBox1.Items.Add(v.nazev);
            }
        }
    }
}